package logic

import (
	"context"
	"shenzhou_srv/models"

	"shenzhou_srv/internal/svc"
	"shenzhou_srv/shenzhou"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartAddLogic {
	return &CartAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartAddLogic) CartAdd(in *shenzhou.CartAddRequest) (*shenzhou.CartAddResponse, error) {
	var err error
	var c models.Cart
	c.Title = in.Title
	c.Image = in.Image
	c.Price = float64(in.Price)
	c.Desc = in.Desc

	if err = c.Create(); err != nil {
		logx.Error("发布失败")
		return nil, err
	}
	return &shenzhou.CartAddResponse{
		CartId: int64(c.ID),
	}, nil
}
